-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Textmate cooperation #4397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Textmate cooperation #4397
Conversation
The change to lifetime coloring is the first screenshot is worse. I definitely prefer it being different from types. |
editors/code/rust.tmGrammar.json
Outdated
@@ -600,7 +600,7 @@ | |||
}, | |||
"core_types": { | |||
"comment": "Built-in/core type", | |||
"name": "storage.type.core.rust", | |||
"name": "entity.name.type.core.rust", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will mean that builtin types no longer get any different syntax highlighting compared to other types, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that’s right. I’m open to changing these choices—the main goal of this PR is just to make the TextMate grammar and the semantic colors consistent with each other, and to fix anything that’s clearly just a mistake/accident inherited from TextMate.
I've discovered a few more subtle disagreements between TextMate and semantic coloring and fixed them:
|
…Mate grammar and other languages
257c2ab
to
63b75a4
Compare
(Rebased) |
…between TextMate and semantic
@aloucks Since changing lifetimes to look like types seems to be controversial, I undid that to keep this PR narrowly focused on harmonizing TextMate and semantic coloring. @bjorn3 right now, TextMate is coloring builtins like keywords, semantic coloring is coloring them like types. Personally I think coloring them like types is better, but I'm happy to go with the consensus either way---we should just be consistent between TextMate and semantic coloring. |
(Edited the description to show before-and-after more clearly) |
I think |
@aloucks Yeah I suppose that's a change as well. It does match the way rust is colored elsewhere, but in the spirit of "let's keep this PR focused on harmonization not change" I put that back. |
|
It might be worth using member for fields which have function types or have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
I am still personally a huge anti-fan of having tmGrammar for Rust at all, (here's the grammar I use), but this is clearly a huge improvement in practice! Thanks @georgewfraser!
| T![while] => h | HighlightModifier::ControlFlow, | ||
| T![while] | ||
| T![in] => h | HighlightModifier::ControlFlow, | ||
T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Build succeeded: |
4436: Use .rust suffix on scopes r=matklad a=georgewfraser This PR should have no effect on people using any of the default themes, but it is possible there are people with custom themes that rely on the .rust suffix on textmate scopes, which I neglected to use consistently in #4397. Co-authored-by: George Fraser <[email protected]>
4400: Enhanced coloring r=georgewfraser a=georgewfraser This PR builds on #4397 to enhance the existing syntax coloring. ## Underline mutable variables The textmate scope `markup.underline` underlines identifiers, which is a nice way to make mutable vars stand out: <img width="327" alt="Screen Shot 2020-05-09 at 1 18 55 PM" src="https://user-images.githubusercontent.com/1369240/81484179-8bb47d80-91f8-11ea-997d-1dcffbe44aa7.png"> ## Italicize static variables The textmate scope `markup.italic` italicizes identifiers. Italic = static is a common convention in IDEs like IntelliJ: <img width="288" alt="Screen Shot 2020-05-09 at 1 19 14 PM" src="https://user-images.githubusercontent.com/1369240/81484236-cd452880-91f8-11ea-8478-505ee49bc8b3.png"> Co-authored-by: George Fraser <[email protected]>
This PR tweaks the fallback TextMate scopes to make them more consistent with the existing grammar and other languages, and edits the builtin TextMate grammar to align with semantic coloring. Before is on the left, after is on the right:
Use keyword.other for regular keywords instead of keyword. This is a really peculiar quirk of TextMate conventions, but virtually all TextMate grammars use
keyword.other
(colored blue in VSCode Dark+) for regular keywords andkeyword.control
(colored purple in VSCode Dark+) for control keywords. The TextMate scopekeyword
is colored like control keywords, not regular keywords. It may seem strange that thekeyword
scope is not the right fallback for thekeyword
semantic token, but TextMate has a long and weird history. Note how keywords change from purple back to blue (what they were before semantic coloring was added):(1) Use punctuation.section.embedded for format specifiers. This aligns with how Typescript colors formatting directives:
(2) Consistently use
entity.name.type.*
scopes for type names. Avoid usingentity.name.*
which gets colored like a keyword.(3) Use Property instead of Member for fields. Property and Member are very similar, but if you look at the TextMate fallback scopes, it's clear that Member is intended for function-like-things (methods?) and Property is intended for variable-like-things.
(4) Color
for
as a regular keyword when it's part ofimpl Trait for Struct
.(5) Use
variable.other.constant
for constants instead ofentity.name.constant
. In the latest VSCode insiders, variable.other.constant has a subtly different color that differentiates constants from ordinary variables. It looks close to the green of types but it's not the same---it's a new color recently added to take advantage of semantic coloring.I also made some minor changes that make the TextMate scopes better match the semantic scopes. The effect of this for the user is you observe less of a change when semantic coloring "activates". You can see the changes I made relative to the built-in TextMate grammar here:
https://github.com/rust-analyzer/rust-analyzer/pull/4397/files/a91d15c80c337dd1afb0eddd5eb048010d098ac7..97428b6d52d25f810dbd7d7a8d787740c58bfbd2#diff-6966c729b862f79f79bf7258eb3e0885